package controller

import (
	"mini-app/internal/app/admin/service"

	"192.168.1.75/go-pkg/response"
	"github.com/gin-gonic/gin"
	"github.com/gin-gonic/gin/binding"
)

type GoodsClass struct{}

// Add 新增分类
func (GoodsClass) Add(c *gin.Context) {
	var params struct {
		Name string `json:"name"`
	}
	c.ShouldBindBodyWith(&params, binding.JSON)
	err := service.GoodsClass{}.Add(c.Request.Context(), params.Name)
	response.JSON(c, nil, err)
}

// Update 更新分类
func (GoodsClass) Update(c *gin.Context) {
	var params struct {
		ID   string `json:"id"`
		Name string `json:"name"`
	}
	c.ShouldBindBodyWith(&params, binding.JSON)
	err := service.GoodsClass{}.Update(c.Request.Context(), params.ID, params.Name)
	response.JSON(c, nil, err)
}

// Delete 删除分类
func (GoodsClass) Delete(c *gin.Context) {
	var params struct {
		ID   string `json:"id"`
		Name string `json:"name"`
	}
	c.ShouldBindBodyWith(&params, binding.JSON)
	err := service.GoodsClass{}.Delete(c.Request.Context(), params.ID)
	response.JSON(c, nil, err)
}

// List 分类列表
func (GoodsClass) List(c *gin.Context) {
	list, _ := service.GoodsClass{}.List(c.Request.Context())
	response.JSON(c, gin.H{
		"list": list,
	}, nil)
}
